package com.kede.repository;

import com.kede.domain.ResourceAreaMap;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @author Pr.li
* @date 2023-04-22
**/
public interface ResourceAreaMapRepository extends JpaRepository<ResourceAreaMap, Integer>, JpaSpecificationExecutor<ResourceAreaMap> {

    @Query(value = "delete from resource_area_map where resource_id in (:resourceIds)",nativeQuery = true)
    @Modifying
    void deleteByResourceIdIn(List<Integer> resourceIds);

    @Query(value = "delete from resource_area_map where area_id = (:areaId) and resource_id = (:resourceId) ",nativeQuery = true)
    @Modifying
    void deleteResourceIdAndAreaId(Integer areaId,Integer resourceId);

    @Query(value = "select resource_id from resource_area_map where area_id in (:areaIds)",nativeQuery = true)
    List<Integer> findResourceIdsByAreaIds(List<Integer> areaIds);

    @Query(value = "select area_id from resource_area_map where resource_id = (:resourceIds)",nativeQuery = true)
    List<Integer> findAreaIdsByResourceIds(Integer resourceIds);
}